using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Gospel.DB
{
    /// <summary>
    /// Controller class for vbsa_articles
    /// </summary>
    [System.ComponentModel.DataObject]
    public partial class ArticleController
    {
        // Preload our schema..
        Article thisSchemaLoad = new Article();
        private string userName = string.Empty;
        protected string UserName
        {
            get
            {
				if (userName.Length == 0) 
				{
    				if (System.Web.HttpContext.Current != null)
    				{
						userName=System.Web.HttpContext.Current.User.Identity.Name;
					}

					else
					{
						userName=System.Threading.Thread.CurrentPrincipal.Identity.Name;
					}

				}

				return userName;
            }

        }

        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public ArticleCollection FetchAll()
        {
            ArticleCollection coll = new ArticleCollection();
            Query qry = new Query(Article.Schema);
            coll.LoadAndCloseReader(qry.ExecuteReader());
            return coll;
        }

        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public ArticleCollection FetchByID(object ArticleId)
        {
            ArticleCollection coll = new ArticleCollection().Where("article_id", ArticleId).Load();
            return coll;
        }

		
		[DataObjectMethod(DataObjectMethodType.Select, false)]
        public ArticleCollection FetchByQuery(Query qry)
        {
            ArticleCollection coll = new ArticleCollection();
            coll.LoadAndCloseReader(qry.ExecuteReader()); 
            return coll;
        }

        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public bool Delete(object ArticleId)
        {
            return (Article.Delete(ArticleId) == 1);
        }

        [DataObjectMethod(DataObjectMethodType.Delete, false)]
        public bool Destroy(object ArticleId)
        {
            return (Article.Destroy(ArticleId) == 1);
        }

        
        
    	
	    /// <summary>
	    /// Inserts a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Insert, true)]
	    public void Insert(string ArticleTitleCn,string ArticleTitleTw,string ArticleTagsCn,string ArticleTagsTw,int FatherId,string ArticleContentCn,string ArticleContentTw,DateTime Created,int PersonId,bool Active)
	    {
		    Article item = new Article();
		    
            item.ArticleTitleCn = ArticleTitleCn;
            
            item.ArticleTitleTw = ArticleTitleTw;
            
            item.ArticleTagsCn = ArticleTagsCn;
            
            item.ArticleTagsTw = ArticleTagsTw;
            
            item.FatherId = FatherId;
            
            item.ArticleContentCn = ArticleContentCn;
            
            item.ArticleContentTw = ArticleContentTw;
            
            item.Created = Created;
            
            item.PersonId = PersonId;
            
            item.Active = Active;
            
	    
		    item.Save(UserName);
	    }

    	
	    /// <summary>
	    /// Updates a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
	    public void Update(int ArticleId,string ArticleTitleCn,string ArticleTitleTw,string ArticleTagsCn,string ArticleTagsTw,int FatherId,string ArticleContentCn,string ArticleContentTw,DateTime Created,int PersonId,bool Active)
	    {
		    Article item = new Article();
		    
				item.ArticleId = ArticleId;
				
				item.ArticleTitleCn = ArticleTitleCn;
				
				item.ArticleTitleTw = ArticleTitleTw;
				
				item.ArticleTagsCn = ArticleTagsCn;
				
				item.ArticleTagsTw = ArticleTagsTw;
				
				item.FatherId = FatherId;
				
				item.ArticleContentCn = ArticleContentCn;
				
				item.ArticleContentTw = ArticleContentTw;
				
				item.Created = Created;
				
				item.PersonId = PersonId;
				
				item.Active = Active;
				
		    item.MarkOld();
		    item.Save(UserName);
	    }

    }

}

